package reflect;

import java.lang.reflect.Method;
import reflect.annotations.AutoRunMethod;
/**
 * 访问方法上的注解
 */
public class ReflectDemo10 {
    public static void main(String[] args) throws Exception {
        //需求:查看Person类上的sayHello方法和sleep方法是否被注解@AutoRunMethod标注了
        Class cls = Class.forName("reflect.Person");
        //获取sayHello方法
        Method method1 = cls.getMethod("sayHello");
        boolean mark1 = method1.isAnnotationPresent(AutoRunMethod.class);
        System.out.println("sayHello方法上是否有@AutoRunMethod:"+mark1);
        //获取sleep方法
        Method method2 = cls.getMethod("sleep");
        boolean mark2 = method2.isAnnotationPresent(AutoRunMethod.class);
        System.out.println("sleep方法上是否有@AutoRunMethod:"+mark2);
    }
}
